Skip to content

Close four places where this node judges a block differently from rskj - #408

Merged
SergioDemianLerner merged 1 commit into
mainfrom
consensus/rskj-parity-divergences
Nov 22, 2026
Merged

SergioDemianLerner merged 1 commit into
mainfrom
consensus/rskj-parity-divergences

Conversation

@SDL-A1

@SDL-A1 SDL-A1 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Four places where this node judged a block differently from rskj. Each is checked against real mainnet history, because a rule stricter than the chain it must accept is a fork, and an argument cannot tell you which one you have written.

1. A header's version is now validated

rskj's BlockHeaderVersionRule runs in both the block rule list and the snap rule list — 0 before RSKIP-351, 1 from it, 2 from RSKIP-535. This node computed the required version for building a header and nothing checked an incoming one.

I confirmed nothing else rejected a mismatch first: header_version had no caller outside the mining template and its own tests. So a header declaring a version its height does not call for was accepted here and refused there.

Against the chain: 1,344 real mainnet headers, all version 0 as required, none rejected. That is now a permanent case in mainnet_block_rules, which also catches the day RSKIP-351 is scheduled and the expectation has to become an activation height rather than a constant.

It also exposed an unrealistic fixture: the uncle tests build headers on regtest, where RSKIP-351 is active from the start, so an unversioned fixture there is not a header the chain would ever carry. They now carry the version their height calls for, stamped before sealing, since the merged-mining proof commits to the hash.

2. Genesis gets rskj's verdict

BlockValidatorImpl.isValid refuses a genesis block outright. validate_block_rules returned Ok(()) for height 0 — the opposite answer to the same question, so any caller branching on the result behaved oppositely on the two clients.

Now GenesisNotValidated. The rules cannot run on genesis either way (it carries no REMASC transaction), so refusing to answer is the honest verdict and it is rskj's. The execution suite confirms nothing depended on the old one.

3. The ommers hash is checked during validation, not only during execution

rskj runs BlockUnclesHashValidationRule inside BlockUnclesValidationRule, i.e. in the block rule list. Here it lived in process_block_inner, which agrees on every path that executes and differs on any that validates without — snap and relay do exactly that. It is now in validate_uncles too, costing one keccak over a list of at most ten headers.

This change found a live defect in the miner. admissible_uncles judges a candidate block with the real import rule, and its comment recorded the assumption the new check broke:

the rule reads the block's number, its parent's hash and its uncles, and nothing else of its header

The candidate inherited the parent's ommers_hash, which is the hash of a different list. Every candidate would have failed, and the miner would have dropped every uncle it was offered — silently, forfeiting the uncle rewards, with only a warning in the log. The candidate now claims the hash of the uncles it names, which is true of any real block.

4. The fork-detection view must be exactly 449

rskj's hasEnoughBlocksToCalculateForkDetectionData refuses a view that is not exactly requiredBlocks. This refused only a short one, and would have computed from the first 449 of a longer one.

The two agree on every input that exists — validate asks for exactly REQUIRED_BLOCKS, and every MainchainView caps at count — so this was a guard that had stopped saying what it meant. It would have become a split through a change to the view builder, which is not a place anyone would look for one.

The miner's mining::fork_detection::calculate keeps < deliberately: it takes the best chain uncapped and returns empty data for a chain too short, as rskj's BlockToMineBuilder does. Both sites now say which they are, so the next person does not "fix" the other.

Tightening it exposed two fixtures feeding the calculator a shape no caller produces — one passing the whole chain and relying on the first 449 being used. They now pass what the validator passes.

Verification

core 378
execution 1,913
sync 670
cli bin 164
mainnet_block_rules (real chain) 5 / 5
clippy --workspace --all-targets clean

The mainnet harness matters most here: it runs the new header-version rule and the uncle rules — including the ommers-hash check — over real blocks from this node's own store, which is the repository's standard for a consensus change.

🤖 Generated with Claude Code

A consensus client that accepts a block the reference client rejects, or the
reverse, puts the two on different chains. Four such places, each the same
shape: a rule rskj runs that this node did not, or a verdict it gives that this
node gave the other way. Each is checked against real mainnet history, because
a rule stricter than the chain it has to accept is a fork and an argument
cannot tell you which one you have written.

**A header's version is now validated.** rskj's `BlockHeaderVersionRule` runs in
both its block rule list and its snap rule list: 0 before RSKIP-351, 1 from it,
2 from RSKIP-535. This node computed the required version for *building* a
header and nothing checked an incoming one, and nothing else rejected a
mismatch either -- `header_version` had no caller outside the mining template
and its tests. So a header declaring a version its height does not call for was
accepted here and refused there. The rule mirrors rskj's, including the genesis
exemption, and an unversioned header answers 0, as rskj's `BlockHeaderV0` does.

Against the chain: 1,344 real mainnet headers, all version 0 as required, none
rejected. That check is now a permanent case in `mainnet_block_rules`, which is
also what catches it if RSKIP-351 is ever scheduled and the expectation has to
become an activation height rather than a constant.

It also found an unrealistic fixture. The uncle tests build headers on regtest,
where RSKIP-351 is active from the start, so an unversioned fixture there is not
a header the chain would carry. They now carry the version their height calls
for, stamped before sealing because the merged-mining proof commits to the hash.

**Genesis gets rskj's verdict.** `BlockValidatorImpl.isValid` refuses a genesis
block outright; `validate_block_rules` returned `Ok(())` for height 0. Opposite
answers to the same question, so any caller that branched on the result behaved
oppositely on the two clients. It now returns `GenesisNotValidated`. The rules
could not run on genesis either way -- it carries no REMASC transaction -- so
refusing to answer is the honest verdict, and it is rskj's. Nothing depended on
the old one.

**The ommers hash is checked during validation, not only during execution.**
rskj runs `BlockUnclesHashValidationRule` inside `BlockUnclesValidationRule`, so
it is in the block rule list. Here it lived in `process_block_inner`, which
agrees on every path that executes and differs on any that validates without --
snap and relay do exactly that. It is now in `validate_uncles` as well, which
costs one keccak over a list of at most ten headers.

That change found a live defect in the miner. `admissible_uncles` judges a
candidate block with the real import rule, and its comment recorded the
assumption the new check broke: "the rule reads the block's number, its parent's
hash and its uncles, and nothing else of its header". The candidate inherited
the *parent's* ommers hash, which is the hash of a different list, so every
candidate would have failed and the miner would have dropped every uncle it was
offered -- silently, with no uncle reward, and only a warning in the log. The
candidate now claims the hash of the uncles it names, which is true of any real
block.

**The fork-detection view must be exactly 449.** rskj's
`hasEnoughBlocksToCalculateForkDetectionData` refuses a view that is not exactly
`requiredBlocks`; this refused only a short one and would have computed from the
first 449 of a longer one. The two agree on every input that exists -- `validate`
asks for exactly `REQUIRED_BLOCKS` and every `MainchainView` caps at `count` --
so this is a guard that stopped saying what it meant, and would have become a
split through a change to the view builder, which is not a place anyone would
look for one.

The miner's `mining::fork_detection::calculate` keeps `<` deliberately: it takes
the best chain uncapped and returns empty data for a chain too short, which is
what rskj's `BlockToMineBuilder` does. Both sites now say which they are, so the
next person does not "fix" the other one.

Tightening it exposed two fixtures feeding the calculator a shape no caller
produces -- one passing the whole chain and leaning on the first 449 being used.
They now pass what the validator passes.

Verified: core 378, execution 1,913, sync 670, cli 164, clippy clean, and all
five `mainnet_block_rules` cases against this node's own block store.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@SergioDemianLerner
SergioDemianLerner merged commit 0fdbf56 into main Nov 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants